package com.example.yuejian21.nongfusanquan.yuejian21.fragment;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerViewAccessibilityDelegate;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.ActivityAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.MatchAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Activitybean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Matchbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Activitymodel;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Matchmodel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Nongfusanquan on 2017-10-10.
 */

public class MatchFragment extends Fragment {
    private RecyclerView recyclerView;
    private TextView activitytitle;
    private View view=null;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        view= inflater.inflate(R.layout.fragment_match, container, false);
        recyclerView=(RecyclerView)view.findViewById(R.id.rv);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(staggeredGridLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());//设置添加,移除item的动画,DefaultItemAnimator为默认的

//        GridLayoutManager layoutManage = new GridLayoutManager(getContext(), 2);
//        recyclerView.setLayoutManager(layoutManage);



        getData();
        return view;
    }



    private void getData() {
        Matchmodel activitymodel=new Matchmodel();
        Call<List<Matchbean>> call=activitymodel.getmatcheslist();
        call.enqueue(new Callback<List<Matchbean>>() {
            @Override
            public void onResponse(Call<List<Matchbean>> call, Response<List<Matchbean>> response) {
                List<Matchbean> data = response.body();  //获取数据
                recyclerView.setAdapter(new MatchAdapter(MatchFragment.this.getActivity(), data));


            }

            @Override
            public void onFailure(Call<List<Matchbean>> call, Throwable t) {

            }
        });

    }

}
